package com.iss.umservice.manager.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.iss.iframework.common.errcode.AppRuntimeException;
import com.iss.umservice.bean.ResourceBean;
import com.iss.umservice.bean.RoleBean;
import com.iss.umservice.dao.RoleDao;
import com.iss.umservice.manager.RoleManager;

/**
 * ��ɫҵ���߼�����
 * 
 * @author suxiaoping
 * @date 2012-8-31
 */
@Service
public class RoleManagerImpl implements RoleManager
{
    
    private final Logger logger = LoggerFactory.getLogger(getClass());
    
    @Autowired
    private RoleDao roleDao;
    
    /**
     * ��ѯ�Ľ�ɫ
     * 
     * @param roleName //��ɫ���
     * @return  list
     */
    public List<RoleBean> queryRoleInfos(String roleName, String systemId,
            int offset, int row) throws AppRuntimeException
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("UserCode [{}] has post roleName request.", roleName);
        }
        
        List<RoleBean> beanList = roleDao.queryRoleInfos(roleName,
                systemId,
                offset,
                row);
        
        return beanList;
        
    }
    
    /**
     * ���ID�Ĳ�ѯ��ɫ
     * 
     * @param roleId //��ɫId
     * @return  RoleBean
     */
    public RoleBean queryRoleInfoByRoleId(String roleId)
            throws AppRuntimeException
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("UserCode [{}] has post roleId request.", roleId);
        }
        
        //��ѯ��ɫ��Ϣ
        RoleBean roleInfo = roleDao.queryRoleInfoByRoleId(roleId);
        
        return roleInfo;
        
    }
    
    /**
     * ���ӽ�ɫ��Ϣ
     * 
     * @param roleBean //��ɫ��Ϣ
     * @return  
     */
    public void addRoleInfo(RoleBean roleBean) throws AppRuntimeException
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("UserCode [{}] has post roleBean request.", roleBean);
        }
        
        roleDao.addRoleInfo(roleBean);
    }
    
    /**
     * ɾ���ɫ��Ϣ
     * 
     * @param roleId //��ɫID
     * @return  
     */
    public void delRoleInfo(String roleId) throws AppRuntimeException
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("UserCode [{}] has post roleId request.", roleId);
        }
        
        //�ж�roleId�Ƿ�Ϊ��
        if (null != roleId && !"".equals(roleId))
        {
            String[] ids = roleId.split(";");
            
            for (int i = 0; i < ids.length; i++)
            {
                //ɾ���ɫ��ϵ
                roleDao.delRoleInfo(ids[i]);
            }
        }
        
    }
    
    /**
     * �޸Ľ�ɫ��Ϣ
     * 
     * @param roleBean //��ɫ��Ϣ
     * @return  
     */
    public void updateRoleInfo(RoleBean roleBean)
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("UserCode [{}] has post roleBean request.", roleBean);
        }
        
        roleDao.updateRoleInfo(roleBean);
    }
    
    /**
     * ��ݽ�ɫID�Ĳ�ѯ��Դ
     * 
     * @param roleId //��ɫId
     * @return  ResourceBean
     */
    public List<ResourceBean> queryResourceInfoByRoleId(String roleId)
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("UserCode [{}] has post roleId request.", roleId);
        }
        List<ResourceBean> beanList = roleDao.queryResourceInfoByRoleId(roleId);
        
        return beanList;
    }
    
    /**
     * �������ͳ�ƽ�ɫ
     * 
     * @param roleName ��ɫ���
     * @return int
     */
    public int countRoleInfo(String roleName, String systemId)
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("UserCode [{}] has post roleName request.", roleName);
        }
        
        return roleDao.countRoleInfo(roleName, systemId);
    }

    public String checkRoleName(String roleName)
    {
        // TODO Auto-generated method stub
        return roleDao.checkRoleName(roleName);
    }

    @Override
    public void updateRoleName(RoleBean roleBean)
    {
        // TODO Auto-generated method stub
        roleDao.updateRoleName(roleBean);
    }
}
